Expand description
A Rust library for parsing, validating, manipulating, and formatting dates and times
Overview
The DateTime (DTT) library is a comprehensive and flexible tool that enables developers to manage dates and times with ease.
It provides drop-in replacement methods for parsing, validating, manipulating, and formatting dates and times in Rust.
The DateTime
type to represent a
date and a time in a defined timezone.
Features
The library DateTime
provides date and time types and methods to
make it easier to manipulate dates and times. It uses the serde
library to derive the Deserialize and Serialize traits to convert
the DateTime
struct to and from various data formats. It also uses
the time and regex crates to deal with time conversions and regular
expressions respectively.
The DateTime
struct includes fields such as:
Feature | Description | Type |
---|---|---|
day | Day of the month: (01-31) | u8 |
hour | Hour of the day: (00-23) | u8 |
iso_8601 | ISO 8601 date and time: (e.g. “2023-01-01T00:00:00+00:00”) | String |
iso_week | ISO week number: (1-53) | u8 |
microsecond | Microsecond: (0-999999) | u32 |
minute | Minute of the hour: (0-59) | u8 |
month | Month: (e.g. “January”) | String |
now | Now object: (e.g. “2023-01-01”) | String |
offset | Offset from UTC: (e.g. “+00:00”) | String |
ordinal | Ordinal date: (1-366) | u16 |
second | Second of the minute: (0-59) | u8 |
time | Time object: (e.g. “00:00:00”) | String |
tz | Time zone object: (e.g. “UTC”) | String |
weekday | Weekday object: (e.g. “Monday”) | String |
year | Year object: (e.g. “2023”) | i32 |
Each of which represents different aspects of a date and time.
Usage
- DateTime can be any
serde::Serialize
orserde::Deserialize
types.
Examples
// Import the DateTime library
extern crate dtt;
use self::dtt::DateTime;
// Create a new DateTime object.
// - The default timezone is UTC.
// - The default date is the current date.
// - The default time is the current time.
// - The default format is ISO 8601.
let dt = DateTime::new();
// Display the current date.
println!("Date: {}", dt.now); // 2023-01-01
// Display the current day.
println!("Day: {}", dt.day); // 01
// Display the current hour.
println!("Hour: {}", dt.hour); // 00
// Display the current ISO 8601 date and time.
println!("ISO 8601: {}", dt.iso_8601); // 2023-01-01T00:00:00+00:00
// Display the current ISO week number.
println!("ISO Week Number: {}", dt.iso_week); // 1
// Display the current microsecond.
println!("Microsecond: {}", dt.microsecond); // 000000
// Display the current minute.
println!("Minute: {}", dt.minute); // 00
// Display the current month.
println!("Month: {}", dt.month); // January
// Display the current offset.
println!("Offset: {}", dt.offset); // +00:00
// Display the current ordinal date.
println!("Ordinal Date: {}", dt.ordinal); // 1
// Display the current second.
println!("Second: {}", dt.second); // 00
// Display the current time.
println!("Time: {}", dt.time); // 00:00:00
// Display the current timezone.
println!("Timezone: {}", dt.tz); // UTC
// Display the current weekday.
println!("Weekday: {}", dt.weekday); // Monday
// Display the current year.
println!("Year: {}", dt.year);
License
The project is licensed under the terms of both the MIT license and the Apache License (Version 2.0).
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Modules
- The
macros
module contains functions for generating macros. Macros for the dtt crate.
Macros
- This macro takes any number of arguments and parses them into a Rust value.
- This macro checks if the given expression is true.
- This macro takes a vector of strings and joins them together into a single string.
- This macro creates a new map of the given key-value pairs.
- This macro returns the maximum of the given values.
- This macro returns the minimum of the given values.
- This macro prints the arguments to the console.
- This macro takes a vector of elements and prints them to the console.
- This macro takes a string and splits it into a vector of words.
- This macro creates a new vector of the given elements.
- This macro generates a function that takes a string as input and returns a boolean.
- This macro takes any number of arguments and parses them into a Rust value.
Structs
- DateTime struct to ease dates and times manipulation.
Functions
- This is the main entry point for the
DateTime (DTT)
library.